﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class EmploymentInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        for (int i = 1; i <= 12; i++)
        {
            ListItem month = new ListItem();
            month.Text = i.ToString();
            DropDownList2.Items.Add(month);
        }
        for (int i = 1; i <= 31; i++)
        {
            ListItem day = new ListItem();
            day.Text = i.ToString();
            DropDownList3.Items.Add(day);
        }
    }

    protected void ExitClick(object sender, EventArgs e)
    {
        Response.Redirect("~/HomePage.aspx", true);
    }

    protected string isNull(string text)
    {
        if(text == "")
            return "无";
        else
            return text;
    }
    protected void bt1_Click(object sender, EventArgs e)
    {
        
        string id = TextBox2.Text;
        string unitName = TextBox3.Text;
        string forward = TextBox4.Text;
        string signAdd = isNull(TextBox5.Text);
        string mdSchool = TextBox6.Text;
        string major = isNull(TextBox7.Text);
        string country = isNull(TextBox8.Text);
        string abordSch = isNull(TextBox9.Text);
        string workName =TextBox10.Text;
        string dept = TextBox11.Text;
        string code = TextBox12.Text;
        string workTime = DropDownList1.SelectedValue+"-"+DropDownList2.SelectedValue+"-"+DropDownList3.SelectedValue;
        string url = isNull(TextBox13.Text);
        string contact = TextBox14.Text;
        string workDept = TextBox15.Text;
        string phone = TextBox16.Text;
        string salary = DropDownList6.SelectedValue;
        string job = TextBox17.Text;
        string workcha = DropDownList5.SelectedValue;

        string conStr = @"Data Source=ADMIN-PC\SQLEXPRESS;Initial Catalog=graduate_manage;Integrated Security=True";

        SqlConnection connection = new SqlConnection(conStr);
        SqlCommand cmd = connection.CreateCommand();

        cmd.Parameters.Add("@unitName", SqlDbType.NVarChar, 200).Value = unitName;
        cmd.Parameters.Add("@id", SqlDbType.VarChar, 20).Value = id;
        cmd.Parameters.Add("@forward", SqlDbType.NVarChar, 200).Value = forward;
        cmd.Parameters.Add("@signAdd", SqlDbType.NVarChar, 200).Value = signAdd;
        cmd.Parameters.Add("@mdSchool", SqlDbType.NVarChar, 200).Value = mdSchool;
        cmd.Parameters.Add("@major", SqlDbType.NVarChar, 50).Value = major;
        cmd.Parameters.Add("@country", SqlDbType.NVarChar, 200).Value = country;
        cmd.Parameters.Add("@abordSch", SqlDbType.NVarChar, 200).Value = abordSch;
        cmd.Parameters.Add("@workName", SqlDbType.NVarChar, 200).Value = workName;
        cmd.Parameters.Add("@dept", SqlDbType.NVarChar, 200).Value = dept;
        cmd.Parameters.Add("@code", SqlDbType.NVarChar, 200).Value = code;
        cmd.Parameters.Add("@workTime", SqlDbType.Date).Value = workTime;
        cmd.Parameters.Add("@url ", SqlDbType.NVarChar, 200).Value = url;
        cmd.Parameters.Add("@contact", SqlDbType.NVarChar, 200).Value = contact;
        cmd.Parameters.Add("@workDept", SqlDbType.NVarChar, 200).Value = workDept;
        cmd.Parameters.Add("@phone", SqlDbType.VarChar, 200).Value = phone;
        cmd.Parameters.Add("@salary", SqlDbType.NVarChar, 20).Value = salary;
        cmd.Parameters.Add("@job", SqlDbType.NVarChar, 20).Value = job;
        cmd.Parameters.Add("@workcha", SqlDbType.NVarChar, 20).Value = workcha;

        using (connection)
        {
            connection.Open();
            cmd.CommandText = "UPDATE EMPLOYINFO_GRADUATE SET "
            + "GRA_ID=@id,EMPLOY_UNITNAME=@unitName,EMPLOY_FORWARD=@forward,EMPLOY_SIGNADD=@signAdd,"
            + "EMPLOY_MDSCHOOL=@mdSchool,EMPLOY_MAJOR=@major,EMPLOY_COUNTRY=@country,EMPLOY_ABORDSCH=@abordSch,EMPLOY_WORKNAME=@workName,EMPLOY_DEPT=@dept," +
            "EMPLOY_CODE=@code,EMPLOY_WORKTIME=@workTime,EMPLOY_URL=@url,EMPLOY_CONTACT=@contact,EMPLOY_WORKDEPT=@workDept, EMPLOY_PHONE=@phone  ,EMPLOY_SALARY=@salary, EMPLOY_JOB=@job, EMPLOY_WORKCHA=@workcha WHERE GRA_ID=@id";
         
            cmd.ExecuteNonQuery();

        }
    }
      
}